import Taro, { getSystemInfoSync as _getSystemInfoSync, request as _request, uploadFile as _uploadFile, getStorageSync as _getStorageSync } from "@tarojs/taro-h5";
import { Config } from './Config';
export const { windowHeight, windowWidth } = _getSystemInfoSync();
export function request(api, data = {}) {
  const { url, method } = api;
  return new Promise(function (resolve, reject) {
    // resolve('123');
    const myData = data; // api.method === 'POST' ? Qs.stringify(data) : data;
    const header = api.method === 'POST' ? {
      'Content-Type': 'application/x-www-form-urlencoded'
    } : {};
    _request({
      url: (api.hasHost ? '' : Config.baseURL) + url,
      method,
      data: myData,
      header,
      dataType: api.dataType || 'json'
    }).catch(error => {
      console.log({ error });
      reject();
    }).then(callback => {
      if (callback) {
        resolve(callback.data);
      } else {
        reject();
      }
    });
  });
}
export function uploadImage(api, filePath, name = '') {
  const formData = {};
  return _uploadFile({
    url: Config.baseURL + api.url,
    filePath,
    name,
    formData
  });
}
export const localHeroData = _getStorageSync('heroData');